﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;

namespace Excel2Words
{
    /// <summary>
    /// 本应用帮助
    /// </summary>
    public class AppHelp
    {
        /// <summary>
        /// 
        /// </summary>
        public const string Title = "Excel2Words";

        public const string App_Description = "从Excel表格文件中读取数据，按Word模板生成与Excel行对应的多个Word文件。";

        public static readonly Color Color_Excel = Color.FromArgb(29, 109, 65);//"29, 109, 65"
        public static readonly Color Color_Word = Color.FromArgb(40, 84, 151);//"40, 84, 151";

        #region TEXT

        public const string RP_BEGIN = "${";
        public const string RP_END = "}$";
        public const string DEMO_COLUMN_NAME = "姓名";

        /// <summary>
        /// 
        /// </summary>
        public const string TEXT_Read_App = App_Description;

        /// <summary>
        /// 
        /// </summary>
        public static readonly string TEXT_Read_Excel = "从Excel文件第一个工作表（Sheet）的 A1 单元格读取表格，" +
                                               "第一行为标题行，第二行开始为数据行，不要使用合并单元格。";

        /// <summary>
        /// 
        /// </summary>
        public static readonly string TEXT_Read_Word = "先制作好Word模板文件，将需要使用Excel哪一列数据替换的，如 " +
                                                        DEMO_COLUMN_NAME +
                                                        "  列替换的位置，使用占位符号 " +
                                                        RP_BEGIN +
                                                        DEMO_COLUMN_NAME +
                                                        RP_END + " 占位。" +
                                                        "";

        /// <summary>
        /// 
        /// </summary>
        public static readonly string TEXT_Read_Help = "关于" + Environment.NewLine + Environment.NewLine +
                                                    "1、程序开发制作：mLaoTang.com （个人网站）" + Environment.NewLine + Environment.NewLine +
                                                    //"2、联系QQ邮箱：575780781@qq.com" + Environment.NewLine + Environment.NewLine +
                                                    "2、联系微信：mLangTang_com" + Environment.NewLine + Environment.NewLine +
                                                    "3、版本号：" + VersionText + Environment.NewLine + Environment.NewLine +
                                                    "4、更新时间：" + Version_Date + " " + Version_Time + Environment.NewLine + Environment.NewLine +
                                                    "" +
                                                    "";

        #endregion

        #region 版本信息

        /// <summary>
        /// 版本号
        /// </summary>
        public static string VersionText
        {
            get
            {
                //object oVersion = HttpRuntime.Cache["VersionText"];
                //if (oVersion != null)
                //{
                //    return oVersion.ToString();
                //}

                if (_versionText == null)
                {
                    Version appVer = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                    if (appVer != null)
                    {
                        string verString = appVer.ToString();
                        _versionText = verString;
                        return verString;
                    }
                    else
                    {
                        _versionText = "-";
                    }
                }
                return _versionText;
            }
        }
        private static string _versionText = null;

        /// <summary>
        /// 版本号_日期
        /// </summary>
        public static string Version_Date
        {
            get
            {
                if (_version_Date == null)
                {
                    RenewVersionDateTime();
                }
                if (_version_Date == null)
                {
                    _version_Date = "-";
                }
                return _version_Date;
            }
        }
        private static string _version_Date;

        /// <summary>
        /// 版本号_时间
        /// </summary>
        public static string Version_Time
        {
            get
            {
                if (_version_Time == null)
                {
                    RenewVersionDateTime();
                }
                if (_version_Time == null)
                {
                    _version_Time = "-";
                }
                return _version_Time;
            }
        }
        private static string _version_Time;

        /// <summary>
        /// 版本号_刷新日期时间
        /// </summary>
        private static void RenewVersionDateTime()
        {
            Version appVer = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            if (appVer == null)
            {
                _version_Date = "-";
                _version_Time = "-";
                return;
            }

            string verString = appVer.ToString();
            string[] ssVerText = verString.Split('.');
            string verDay = null; //编译日期(从2000-1-1到编译日的天数)
            string verTime = null; //编译时间(从 0:00:00到编译时的刻度数/两秒数)

            //日期
            if (ssVerText.Length >= 3)
            {
                //第3位是日期
                string s = ssVerText[2];
                if (Regex.IsMatch(s, @"^\d{1,}$"))
                {
                    int day;
                    if (int.TryParse(s, out day))
                    {
                        //编译日期
                        verDay = (new DateTime(2000, 1, 1)).AddDays(day).ToString("yyyy-MM-dd");
                    }
                }
            } //日期

            //时间
            if (ssVerText.Length >= 4)
            {
                string s = ssVerText[3];
                if (Regex.IsMatch(s, @"^\d{1,}$"))
                {
                    int second2;
                    if (int.TryParse(s, out second2))
                    {
                        //编译时间
                        DateTime dt = (new DateTime(2000, 1, 1, 0, 0, 0, 0));
                        DateTime dt2 = dt.AddSeconds(second2 * 2); //两秒
                        verTime = dt2.ToString("HH:mm"); //verTime = dt2.ToString("HH:mm:ss");
                    }
                }
            } //时间

            if (string.IsNullOrEmpty(verDay)) verDay = "-";
            if (string.IsNullOrEmpty(verTime)) verTime = "-";

            //设置
            _version_Date = verDay;
            _version_Time = verTime;
        }

        #endregion

    }
}
